package com.capgemini.teamtwo.common;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.http.HttpStatus;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class ResponseBean<T> {

    private int code;
    private String message;
    private T data;

    public static <T> ResponseBean success(T data) {
        return ResponseBean.builder()
                .code(HttpStatus.OK.value())
                .message(HttpStatus.OK.getReasonPhrase())
                .data(data)
                .build();
    }

    public static <T> ResponseBean failed() {
        return ResponseBean.builder()
                .code(HttpStatus.INTERNAL_SERVER_ERROR.value())
                .message(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase())
                .build();
    }

    public static <T> ResponseBean failed(String message) {
        return ResponseBean.builder()
                .code(HttpStatus.BAD_REQUEST.value())
                .message(message)
                .build();
    }

    public static <T> ResponseBean failed(int code, String message) {
        return ResponseBean.builder()
                .code(code)
                .message(message)
                .build();
    }

    public static <T> ResponseBean failed(int code, String message, Object data) {
        return ResponseBean.builder()
                .code(code)
                .message(message)
                .data(data)
                .build();
    }

}
